package com.ywh.hilttest.test4

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import com.ywh.hilttest.test5.SingletonGlobal
import com.ywh.hilttest.test5.SingletonSdkGlobal
import com.ywh.hilttest.test6.SingletonActivity
import com.ywh.hilttest.test6.SingletonSdkActivity
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class FragmentObjectBind : Fragment() {

    //一个对象有多个子类，我们怎么让hilt知道我们要子类
    @BindsCarEngine
    @Inject
    lateinit var engine1: Engine

    @BindsTrainEngine
    @Inject
    lateinit var engine2: Engine






    //全局单例
    @Inject
    lateinit var singletonGlobal: SingletonGlobal

    @Inject
    lateinit var singletonSdkGlobal: SingletonSdkGlobal


    //同一Activity单例
    @Inject
    lateinit var singletonActivity: SingletonActivity

    @Inject
    lateinit var singletonActivity2: SingletonActivity


    //同一Activity单例
    @Inject
    lateinit var singletonSdkActivity: SingletonSdkActivity

    @Inject
    lateinit var singletonSdkActivity2: SingletonSdkActivity

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val name1 = engine1.name()
        val name2 = engine2.name()

        Log.e("HiltTest", "name1:${name1}")

        Log.e("HiltTest", "name2:${name2}")

        Log.e("HiltTest", "SingletonGlobal-hashCode in ${this::class.java.simpleName}:${singletonGlobal.hashCode()}")
        Log.e("HiltTest", "SingletonSdkGlobal-hashCode in ${this::class.java.simpleName}:${singletonSdkGlobal.hashCode()}")
        Log.e("HiltTest", "SingletonActivity-hashCode in ${this::class.java.simpleName}:${singletonActivity.hashCode()},${singletonActivity2.hashCode()}")
        Log.e("HiltTest", "SingletonSdkActivity-hashCode in ${this::class.java.simpleName}:${singletonSdkActivity.hashCode()},${singletonSdkActivity2.hashCode()}")

    }
}